package com.ylpsk.live;

import android.app.Application;
import android.content.Context;

import com.eduhdsdk.tools.ScreenScale;
import com.eduhdsdk.tools.Tools;
import com.llew.huawei.verifier.LoadedApkHuaWei;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * Created by Administrator on 2018/4/17.
 */

public class MyApplication extends Application {
    public static MyApplication context;

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
//        Reflection.unseal(base);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        context = this;
        ScreenScale.init(this);//适配方案
//        TKPluginsManager.getInstance().setContext(this).setShareData("appId"/微信,"appSecret"/微信).setStatisticsData("appId","channel").init();//配置umeng 具体详见2.5
        //解决通过反射解决在HuaWei手机出现Register too many Broadcast Receivers的crash
        if (!Tools.phoneIsSony(context)) {
            LoadedApkHuaWei.hookHuaWeiVerifier(this);
        }
    }

    /**
     * 关闭弹窗
     */
    private void closeAndroidPDialog() {
        try {
            Class aClass = Class.forName("android.content.pm.PackageParser$Package");
            Constructor declaredConstructor = aClass.getDeclaredConstructor(String.class);
            declaredConstructor.setAccessible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Class cls = Class.forName("android.app.ActivityThread");
            Method declaredMethod = cls.getDeclaredMethod("currentActivityThread");
            declaredMethod.setAccessible(true);
            Object activityThread = declaredMethod.invoke(null);
            Field mHiddenApiWarningShown = cls.getDeclaredField("mHiddenApiWarningShown");
            mHiddenApiWarningShown.setAccessible(true);
            mHiddenApiWarningShown.setBoolean(activityThread, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static MyApplication getInstance() {
        return context;
    }
}
